package rsj.dao;

import java.sql.Connection;
import java.sql.SQLException;

import rsj.table.Menu;
import rsj.table.Rome;
import rsj.table.User;

import com.rlyy.aibase.db.QueryRunner;
import com.rlyy.aibase.utils.base.TableNode;



public class MenuInfoDao {
	
	private static final MenuInfoDao infoDao = new MenuInfoDao();
	
	 public static MenuInfoDao getInstance(){
	        return infoDao;
	 }
	 
	 public TableNode findMenuAuth(Connection conn,String userId) throws SQLException{
		 QueryRunner queryRunner = new QueryRunner();
		 
		 StringBuffer findsql = new StringBuffer();
		 findsql.append("select "+Menu.Menu_Id+","+Menu.Menu_Pid+","+Menu.Menu_Title+","+Menu.Menu_Level+","+Menu.Menu_Url);
		 findsql.append(" from (select "+Rome.Rome_Menu_Id+" from "+Rome.Table_Name+" where "+Rome.Rome_Role_Id)
		 		.append(" = (select "+User.User_Role_Id +" from "+User.Table_Name +" where "+User.User_Id+" = ?))rm")
		 		.append(" left join "+Menu.Table_Name+" m on rm."+Rome.Rome_Menu_Id+"= m."+Menu.Menu_Id);
		 
		 TableNode map = queryRunner.queryLinkTableNode(conn,findsql.toString(),userId);
		 return map;
		 
	 }
	 
	 public TableNode findAllMenu(Connection conn,String userId) throws SQLException{
		 QueryRunner queryRunner = new QueryRunner();
		 
		 StringBuffer findsql = new StringBuffer();
		 findsql.append("select "+Menu.Menu_Id+","+Menu.Menu_Pid+","+Menu.Menu_Title)
		 		 .append(" from "+Menu.Table_Name);
		 
		 TableNode map = queryRunner.queryLinkTableNode(conn,findsql.toString());
		 return map;
	 }

}
